package cc.laop.business.system;

import cc.laop.business.BaseBusinessImpl;
import cc.laop.dao.system.ConfigMapper;
import cc.laop.entity.system.Config;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ConfigBusiness extends BaseBusinessImpl<ConfigMapper, Config> {

    public void update(List<Config> list) {
        if (list != null && list.size() > 0) {
            for (Config config : list) {
                if (config.getId() > 0) {
                    super.update(config);
                }
            }
        }
    }

    public String getConfig(String key) {
        Config config = new Config();
        config.setKey(key);
        List<Config> list = super.select(config);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0).getValue();
        } else {
            return null;
        }
    }

}
